#include <bits/stdc++.h>

using namespace std;
#define int long long
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 2e5 + 10;

int color[N];
int a[N], c[N];
int ans, n;

void dfs(int u)
{
	if (u > n)
	{
		int res = 0;
		for (int i = 0; i < n; i ++ )
			res += c[i];
		//for (int i = 0; i < n; i ++ )
			//cout << color[i] << ' ';
			//cout << endl;
		ans = max(res, ans);
		return;
	}
	for (int i = 1; i < 3; i ++ )
	{
		color[u] = i;
		for (int j = u - 1; j >= 0; j -- )
			if (color[j] == i)
			{
				if (a[u] == a[j]) c[u] = a[u];
				break;
			}
		dfs(u + 1);
		c[u] = 0;
		color[u] = 0;
	}
}

void solve()
{
	ans = 0;
	cin >> n;
	for (int i = 0; i < n; i ++ )
		cin >> a[i];
	dfs(0);
	cout << ans << endl;
}

signed main()
{
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	ios::sync_with_stdio(false);
	int T;
	cin >> T;
	while (T -- )
	{
		memset(color, 0, sizeof color);
		memset(a, 0, sizeof a);
		memset(c, 0, sizeof c);
		solve();
	}
	return 0;
}
